package com.com.knowledgepaymentmanagementsystem.controller.marketing;
import com.com.knowledgepaymentmanagementsystem.pojo.marketing.Menu;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.com.knowledgepaymentmanagementsystem.service.marketing.MenuService;
import java.util.List;

/**
 * @author DELL
 * @version 1.0
 * @description: TODO
 * @date 2025/9/23 15:54
 */
@RestController
@Api(tags = "套餐管理")
@CrossOrigin
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    @ApiOperation(value = "查询套餐", httpMethod = "POST", notes = "查询套餐")
    @PostMapping("/find")
    public ResultUtil<List<Menu>> getMenu(@RequestBody Menu menu){
        List<Menu> menus = menuService.getMenu(menu);
        try {
            return new ResultUtil<>(200, "查询成功", menus);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询失败");

        }
    }

    @ApiOperation(value = "新增套餐", httpMethod = "POST", notes = "新增套餐")
    @PostMapping("insert")
    public ResultUtil insertMenu(@RequestBody Menu menu) {
        try {
            return new ResultUtil<>(200, "新增成功", menuService.insertMenu(menu));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "新增失败");
        }
    }

    @ApiOperation(value = "删除套餐", httpMethod = "DELETE", notes = "删除套餐")
    @DeleteMapping("delete")
    public ResultUtil deleteMenu(@RequestParam Integer menuId) {
        try {
            menuService.deleteMenu(menuId);
            return new ResultUtil<>(200, "删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "删除失败");
        }

    }

    @ApiOperation(value = "修改套餐", httpMethod = "PUT", notes = "修改套餐")
    @PutMapping("update")
    public ResultUtil updateMenu(@RequestBody Menu menu) {
        try {
            menuService.updateMenu(menu);
            return new ResultUtil<>(200, "修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "修改失败");
        }
    }



}
